#  -*- coding:utf-8 -*- 
"""
@ author: 罗金盛
@ time: 2024/7/15 
@ file: get_challenge.py

参考网址：
https://www.52pojie.cn/thread-1940566-1-1.html
"""
import requests
import time

time_ = str(int(time.time())*1000)
cookies = {
    # 'sensorsdata2015jssdkcross': '%7B%22distinct_id%22%3A%2218ec71e6c8beaa-04e477f55315fbc-26001a51-1517208-18ec71e6c8c17ba%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E5%BC%95%E8%8D%90%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC%22%2C%22%24latest_referrer%22%3A%22https%3A%2F%2Fwww.sf-express.com%2F%22%2C%22%24latest_landing_page%22%3A%22https%3A%2F%2Fwww.geetest.com%2FHelper%22%7D%2C%22%24device_id%22%3A%2218ec71e6c8beaa-04e477f55315fbc-26001a51-1517208-18ec71e6c8c17ba%22%7D',
    # 'Hm_lvt_25b04a5e7a64668b9b88e2711fb5f0c4': '1712737644',
}

headers = {
    'accept': 'application/json, text/javascript, */*; q=0.01',
    'accept-language': 'zh-CN,zh;q=0.9',
    'cache-control': 'no-cache',
    # 'cookie': 'sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2218ec71e6c8beaa-04e477f55315fbc-26001a51-1517208-18ec71e6c8c17ba%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E5%BC%95%E8%8D%90%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC%22%2C%22%24latest_referrer%22%3A%22https%3A%2F%2Fwww.sf-express.com%2F%22%2C%22%24latest_landing_page%22%3A%22https%3A%2F%2Fwww.geetest.com%2FHelper%22%7D%2C%22%24device_id%22%3A%2218ec71e6c8beaa-04e477f55315fbc-26001a51-1517208-18ec71e6c8c17ba%22%7D; Hm_lvt_25b04a5e7a64668b9b88e2711fb5f0c4=1712737644',
    'pragma': 'no-cache',
    'priority': 'u=1, i',
    'referer': 'https://www.geetest.com/demo/slide-float.html',
    'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
    'x-requested-with': 'XMLHttpRequest',
}

params = {
    't':time_,
}

response = requests.get('https://www.geetest.com/demo/gt/register-slide', params=params, cookies=cookies, headers=headers)
challenge = response.json()['challenge']
gt = response.json()['gt']
print(challenge,gt)

headers = {
    'accept': '*/*',
    'accept-language': 'zh-CN,zh;q=0.9',
    'cache-control': 'no-cache',
    # 'cookie': 'sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2218ec71e6c8beaa-04e477f55315fbc-26001a51-1517208-18ec71e6c8c17ba%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E5%BC%95%E8%8D%90%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC%22%2C%22%24latest_referrer%22%3A%22https%3A%2F%2Fwww.sf-express.com%2F%22%2C%22%24latest_landing_page%22%3A%22https%3A%2F%2Fwww.geetest.com%2FHelper%22%7D%2C%22%24device_id%22%3A%2218ec71e6c8beaa-04e477f55315fbc-26001a51-1517208-18ec71e6c8c17ba%22%7D; Hm_lvt_25b04a5e7a64668b9b88e2711fb5f0c4=1712737644; GeeTestUser=cca4cd441497351a444314862a7a87ce',
    'pragma': 'no-cache',
    'referer': 'https://www.geetest.com/',
    'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'script',
    'sec-fetch-mode': 'no-cors',
    'sec-fetch-site': 'same-site',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
}

params = {
    'gt': gt,
    'callback': f'geetest_{time_}',
}

response = requests.get('https://apiv6.geetest.com/gettype.php', params=params, cookies=cookies, headers=headers)
print(response.text)




"""
{
    "$_CAAG": 1721094320926,
    "protocol": "https://",
    "gt": "019924a82c70bb123aae90d483087f94",
    "challenge": "0f66ae78ba9a329da4bf0c929647a2bf",
    "offline": false,
    "new_captcha": true,
    "product": "float",
    "width": "300px",
    "https": true,
    "api_server": "apiv6.geetest.com",
    "type": "fullpage",
    "static_servers": [
        "static.geetest.com/",
        "static.geevisit.com/"
    ],
    "beeline": "/static/js/beeline.1.0.1.js",
    "voice": "/static/js/voice.1.2.4.js",
    "click": "/static/js/click.3.1.0.js",
    "fullpage": "/static/js/fullpage.9.1.9-dbjg5z.js",
    "slide": "/static/js/slide.7.9.2.js",
    "geetest": "/static/js/geetest.6.0.9.js",
    "aspect_radio": {
        "slide": 103,
        "click": 128,
        "voice": 128,
        "beeline": 50
    },
    "cc": 16,
    "supportWorker": true,
    "$_FEw": {
        "pt": 0
    },
    "aeskey": "8bc671fc08398a5b"
}
"""